import math

def prime(n):
    if n < 2:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime_number(num):
    if num.isdigit():
        print("Wrong input")
        return

    num_names = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    number = 0
    for i in num.split():
        number = number * 10 + num_names.index(i)

    if prime(number):
        print(number)
        return

    lower = number + 1
    upper = number - 1
    while True:
        if prime(lower):
            print(lower)
            return
        elif prime(upper):
            print(upper)
            return
        lower -= 1
        upper += 1

nums = input().strip()
closest_prime_number(nums)